﻿using AutoCommunication.Base;
using AutoCommunication.Helper;
using System;

#if NET461_OR_GREATER || NET5_0_OR_GREATER

namespace AutoCommunication
{
    public partial class ChangeVarableValue : System.Windows.Forms.Form
    {
        public ChangeVarableValue()
        {
            InitializeComponent();
        }

        private string devName;
        private BaseVariable variable;

        public ChangeVarableValue(string Name)
        {
            InitializeComponent();
            var add = Name.Split('.');
            devName = add[0];//设备名
            variable = Auto.AllVarable[Name];
            textBox1.Text = variable.Address;
            textBox2.Text = variable.DataType.ToString();
            textBox3.Text = variable.Value.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double varlue;
            Result res = new Result();
            if (double.TryParse(textBox4.Text, out varlue))
            {
                // res = await Auto.AllDevice[devName.Norm()].WriteAsync(variable.Name, varlue);
            }
            else
            {
                res.IsSucceed = false;
            }
            if (res.IsSucceed)
            {
                this.Close();
            }
        }
    }
}

#endif